const sys = require(`./system.js`)
const title = '记录转卖用户'
const $ = sys.$(title)

sys.run($, 'task:one2', (resList, cookie, index, username, password, item) => {
    return new Promise(async resolve => {
        // 查询转卖列表
        const resp1 = await $.publicJS.userPhoneList($, cookie)
        const list = resp1.map(it => ({
          id: it.id,
          createdDate: it.createdDate,
          phone: it.phone,
          userCurrentAmount: it.userCurrentAmount,
          historyAmount: it.historyAmount,
          headImg: it.headImg,
          wechatNickName: it.wechatNickName,
        }))
        resList.push(...list)
        return resolve(resList)
    })
}, (resList) => {
    console.log('任务结束 resList:', resList)
    let userList = $.localStorage.get('task:userList', 'localStorageInfo') || []

    userList.push(...resList)
    const newUserList = $.publicJS.unique(userList, "id").map((it, idx) => ({
      index: idx,
      ...it,
    }))
    $.localStorage.set('task:userList', newUserList, 'localStorageInfo')
})
